unit Class_DICT;

interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TDICT=class(TUniEngine)
  private
    FDICTIDEX : Integer;          
    FDICTMODE : string;
    FDICTINFO : string;
    FDICTCODE : string;
    FDICTNAME : string;
    FDICTMEMO : string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property DICTIDEX : Integer read FDICTIDEX  write FDICTIDEX;
    property DICTMODE : string read FDICTMODE  write FDICTMODE;
    property DICTINFO : string read FDICTINFO  write FDICTINFO;
    property DICTCODE : string read FDICTCODE  write FDICTCODE;
    property DICTNAME : string read FDICTNAME  write FDICTNAME;
    property DICTMEMO : string read FDICTMEMO  write FDICTMEMO;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(ADICT:TDICT):TDICT;overload;        
    class procedure CopyIt(ADICT:TDICT;var Result:TDICT);overload;       
  end;

implementation

{ TDICT }
procedure TDICT.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('DICT_IDEX').Value := DICTIDEX;
        ParamByName('DICT_MODE').Value := DICTMODE;
        ParamByName('DICT_INFO').Value := DICTINFO;
        ParamByName('DICT_CODE').Value := DICTCODE;
        ParamByName('DICT_NAME').Value := DICTNAME;
        ParamByName('DICT_MEMO').Value := DICTMEMO; 
      end;
      otEdit:
      begin
        ParamByName('DICT_IDEX').Value := DICTIDEX;
        ParamByName('DICT_MODE').Value := DICTMODE;
        ParamByName('DICT_INFO').Value := DICTINFO;
        ParamByName('DICT_CODE').Value := DICTCODE;
        ParamByName('DICT_NAME').Value := DICTNAME;
        ParamByName('DICT_MEMO').Value := DICTMEMO; 
      end;  
      otDelt:
      begin
        ParamByName('DICT_IDEX').Value := DICTIDEX;
 
      end;  
    end;
  end;
end;

function TDICT.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('GWK_DICT',['DICT_IDEX',DICTIDEX],AUniConnection);
end;

function TDICT.GetNextIdex: Integer;
begin

end;

function TDICT.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin
  Result:=CheckField('DICT_IDEX','GWK_DICT',[],AUniConnection);
end;

function TDICT.GetStrDelete: string;
begin
  Result:='DELETE FROM GWK_DICT WHERE   DICT_IDEX=:DICT_IDEX';
end;

function TDICT.GetStrInsert: string;
begin
  Result:='INSERT INTO GWK_DICT'
         +'    ( DICT_IDEX, DICT_MODE, DICT_INFO, DICT_CODE, DICT_NAME'
         +'    , DICT_MEMO)'
         +'    VALUES'
         +'    (:DICT_IDEX,:DICT_MODE,:DICT_INFO,:DICT_CODE,:DICT_NAME'
         +'    ,:DICT_MEMO)';
end;

function TDICT.GetStrsIndex: string;
begin
  Result:=Format('%D',[DICTIDEX]);
end;

function TDICT.GetStrUpdate: string;
begin
  Result:='UPDATE  GWK_DICT SET'
         +'    DICT_MODE=:DICT_MODE,'
         +'    DICT_INFO=:DICT_INFO,'
         +'    DICT_CODE=:DICT_CODE,'
         +'    DICT_NAME=:DICT_NAME,'
         +'    DICT_MEMO=:DICT_MEMO'
         +'    WHERE DICT_IDEX=:DICT_IDEX';
end;

constructor TDICT.Create;
begin

end;

destructor TDICT.Destroy;
begin

  inherited;
end;

class function TDICT.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
begin
  Result:=TDICT.Create;

  with TDICT(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      if Field.FieldName='DICT_IDEX' then
      begin
        DICTIDEX :=Field.AsInteger;
      end else
      if Field.FieldName='DICT_MODE' then
      begin
        DICTMODE :=Field.AsString;
      end else
      if Field.FieldName='DICT_INFO' then
      begin
        DICTINFO :=Field.AsString;
      end else
      if Field.FieldName='DICT_CODE' then
      begin
        DICTCODE :=Field.AsString;
      end else
      if Field.FieldName='DICT_NAME' then
      begin
        DICTNAME :=Field.AsString;
      end else
      if Field.FieldName='DICT_MEMO' then
      begin
        DICTMEMO :=Field.AsString;
      end;
    end
  end;  
end;

class procedure TDICT.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
begin
  if Result=nil then Exit;

  with TDICT(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      if Field.FieldName='DICT_IDEX' then
      begin
        DICTIDEX :=Field.AsInteger;
      end else
      if Field.FieldName='DICT_MODE' then
      begin
        DICTMODE :=Field.AsString;
      end else
      if Field.FieldName='DICT_INFO' then
      begin
        DICTINFO :=Field.AsString;
      end else
      if Field.FieldName='DICT_CODE' then
      begin
        DICTCODE :=Field.AsString;
      end else
      if Field.FieldName='DICT_NAME' then
      begin
        DICTNAME :=Field.AsString;
      end else
      if Field.FieldName='DICT_MEMO' then
      begin
        DICTMEMO :=Field.AsString;
      end;
    end
  end;  
end;

class function  TDICT.CopyIt(ADICT: TDICT): TDICT;
begin
  Result:=TDICT.Create;
  TDICT.CopyIt(ADICT,Result)
end;

class procedure TDICT.CopyIt(ADICT:TDICT;var Result:TDICT);
begin
  if Result=nil then Exit;
  Result.DICTIDEX :=ADICT.DICTIDEX;
  Result.DICTMODE :=ADICT.DICTMODE;
  Result.DICTINFO :=ADICT.DICTINFO;
  Result.DICTCODE :=ADICT.DICTCODE;
  Result.DICTNAME :=ADICT.DICTNAME;
  Result.DICTMEMO :=ADICT.DICTMEMO;
end;

end.

